package com.mrjy.maintain.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.mrjy.common.entity.UserBalanceInfo;
import com.mrjy.common.entity.UserInfo;
import com.mrjy.common.util.GlobalConstant;
import com.mrjy.maintain.bo.IUserBalanceInfoBo;
import com.mrjy.maintain.bo.IUserInfoBo;

@Controller
@RequestMapping("/maintain/userBalanceInfo")
public class UserBalanceInfoController {

	@Resource
	private IUserBalanceInfoBo userBalanceInfoBo;
	
	@Resource IUserInfoBo userInfoBo;
	/**
	 * 根据用户id 查询余额信息并更新，如果余额表没有记录，则新增一条余额为0的并返回
	 * @param session
	 * @return
	 * @author csshui isUse=true
	 */
	@RequestMapping("/queryUserBalance")
	@ResponseBody
	public Object queryUserBalance(HttpSession session) {
		UserInfo userInfo = (UserInfo) session
				.getAttribute(GlobalConstant.USER_INFO);
		return userBalanceInfoBo.queryByUserId(userInfo);
	}
	
	@RequestMapping("/queryUserBalanceByMobilePhone")
	@ResponseBody
	public Object queryUserBalanceByMobilePhone(String mobilePhone) {
		return userBalanceInfoBo.queryByMobielPhone(mobilePhone);
	}
	
	
	/**
	 * TODO 修改重置方法，没有做事务处理 
	 * 重置支付密码
	 * @param session
	 * @param userBalanceInfo userBalanceInfo.payPasswordString 新的支付密码
	 * @param mobilePhoneCode 验证码
	 * @param request
	 * @author csshui isUser = true
	 * @return
	 */
	@RequestMapping("/resetPayPw")
	@ResponseBody
	public Object resetPayPw(HttpSession session,UserBalanceInfo userBalanceInfo, String mobilePhoneCode,
			HttpServletRequest request) {
		UserInfo sessionUserInfo = (UserInfo) session.getAttribute(GlobalConstant.USER_INFO);
		//HashMap<String, String> map = (HashMap<String, String>) session.getAttribute(GlobalConstant.RANDOM_PhoneCODE_KEY);		
		Object mark = userBalanceInfoBo.resetPayPW(sessionUserInfo,userBalanceInfo,mobilePhoneCode);

		return mark;
	}
	
}
